/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tkgarment.system.dao;

import com.tkgarment.system.domain.BloodType;
import com.tkgarment.system.factory.DAOFactory;
import com.tkgarment.system.inf.IDAO;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author zraj
 */
public class BloodTypeDAO extends AbstractDAO implements IDAO<BloodType, Integer> {

    @Override
    public List<BloodType> getAll() throws Exception {
        String sql = "select * from blood_type order by " + BloodType.field_blood_type_name + " ASC " ;
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        
        List<Map<String, Object>> result = this.getCon().queryList(sql);
        List<BloodType> bloodTypes = new ArrayList<>();
        for (Map<String, Object> map : result) {
            BloodType b = new BloodType();
            b.setBloodType(Integer.parseInt(map.get(BloodType.field_blood_type_id).toString()));
            b.setBloodTypeName(map.get(BloodType.field_blood_type_name).toString());
            bloodTypes.add(b);
        }
        return bloodTypes;
    }

    @Override
    public int updateSingle(BloodType t, Integer id) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int deleteSingle(BloodType t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int insertSingle(BloodType t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public BloodType getById(Integer id) throws Exception {
         String sql = "select * from blood_type where "+ BloodType.field_blood_type_id +"  = ?" ;
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        
        Map<String, Object> map = this.getCon().querySingle(sql,id);
        
            BloodType b = new BloodType();
            b.setBloodType(Integer.parseInt(map.get(BloodType.field_blood_type_id).toString()));
            b.setBloodTypeName(map.get(BloodType.field_blood_type_name).toString());
           
        return b;
    }

   
}
